#include<stdio.h>
#include<string.h>
#include<string>
#include <algorithm>
#include<iostream>
using namespace std;
int main()
{
	int m1, m2, r1, r2, r3;
	string com;//command
	while (cin >> m1 >> m2 >> com)
	{
		r1 = r2 = r3 = 0;
		for (int i = 0; i < com.size(); i++)
		{
			switch (com[i])
			{
			case 'A':r1 = m1; break;
			case 'B':r2 = m2; break;
			case 'C':m1 = r3; break;
			case 'D':m2 = r3; break;
			case 'E':r3 = r1 + r2; break;
			case 'F':r3 = r1 - r2; break;
			default:
				break;
			}
		}
		cout << m1 << "," << m2 << endl;
	}
	return 0;
}